﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BacteriaSimulation.Simulation
{
    public class DetectWallCollisionTask : AbstractTask
    {

        public override TaskOutcome executeTask(Simulation simulation, Bacterium bacterium, SimulationEnvironment env)
        {
            if (bacterium.X > (env.Width - bacterium.Width))
            {
                bacterium.X = env.Width - bacterium.Width - env.Epsilon;
                bacterium.WallCollisionDetected(WALL_COLLISION_TYPE.RIGHT, env);
            }
            if (bacterium.X < 0)
            {
                bacterium.X = 0 + env.Epsilon;
                bacterium.WallCollisionDetected(WALL_COLLISION_TYPE.LEFT, env);
            }
            if (bacterium.Y < 0)
            {
                bacterium.Y = 0 + env.Epsilon;
                bacterium.WallCollisionDetected(WALL_COLLISION_TYPE.TOP, env);
            }
            if (bacterium.Y > (env.Height - bacterium.Height))
            {
                bacterium.Y = (env.Height - bacterium.Height - env.Epsilon);
                bacterium.WallCollisionDetected(WALL_COLLISION_TYPE.BOTTOM, env);
            }

            return new TaskOutcome(TaskOutcomeType.CONTINUE);
        }
    }
}
